package com.situ.mall.notification.api.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.situ.mall.notification.api.mapper.NotificationMapper;
import com.situ.mall.notification.spi.model.Notification;
import com.situ.mall.notification.spi.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NotificationServiceImpl implements NotificationService {

    private NotificationMapper notificationMapper;

    @Autowired
    public void setNotificationMapper(NotificationMapper notificationMapper) {
        this.notificationMapper = notificationMapper;
    }

    @Override
    public Page<Notification> findAll(Page<Notification> page, Notification notification) {
        return notificationMapper.findAll(page,notification);
    }

    @Override
    public Notification findById(Integer id) {
        return notificationMapper.selectById(id);
    }

    @Override
    public boolean save(Notification notification) {
        return notificationMapper.insert(notification)==1;
    }

    @Override
    public boolean update(Notification notification) {
        return notificationMapper.updateById(notification)==1;
    }

    @Override
    public int deleteByIds(List<Integer> ids) {
        return notificationMapper.deleteByIds(ids);
    }

    @Override
    public boolean saveIds(int[] ids) {
        return true;
    }

    @Override
    public Page<Notification> findUserNotifications(Page<Notification> page, Integer userId) {
        return notificationMapper.findUserNotifications(page, userId);
    }

    @Override
    public Integer getUnreadNotificationCount(Integer userId) {
        return notificationMapper.getUnreadNotificationCount(userId);
    }

    @Override
    public boolean markNotificationAsRead(Integer notificationId) {
        return notificationMapper.markNotificationAsRead(notificationId);
    }

    @Override
    public boolean markAllNotificationsAsRead(Integer userId) {
        return notificationMapper.markAllNotificationsAsRead(userId);
    }

}
